package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.ClassGrade;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IClassGradeService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.Date;
import java.util.List;


@Controller
@RequestMapping("classgrade")
public class ClassGradeController {


    @Autowired
    private IClassGradeService classGradeService;


    //跳转主页
    @RequestMapping("")
    public String index(){
        return "classgrade";
    }

    //班级数据表
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
       return  classGradeService.query(qo);
    }


    //班级新增
    @RequestMapping("save")
    @ResponseBody
    public JsonResult saveClass(ClassGrade classGrade){
        JsonResult jsonResult = new JsonResult();
        try{
            classGradeService.insertClass(classGrade);
        }catch(Exception e){
            e.printStackTrace();
            jsonResult.setMsg("添加失败啦......你等会再来");
        }
        return jsonResult;
    }
    //班级编辑
    @RequestMapping("update")
    @ResponseBody
    public JsonResult updateClass(ClassGrade classGrade){
        JsonResult jsonResult = new JsonResult();
        try{
            classGradeService.updateClass(classGrade);
        }catch(Exception e){
            e.printStackTrace();
            jsonResult.setMsg("编辑失败啦......你等会再来");
        }
        return jsonResult;
    }

    //陈遵汉专属 勿删
    //查询所有班级 以json格式返回 用于前端下拉列表 回填数据
    @RequestMapping("listAllClassGradeJson")
    @ResponseBody
    public List<ClassGrade> listAllClassGradeJson() {
        return classGradeService.listAllClassGradeJson();
    }

    /*查询出所有的基础班*/
    @RequestMapping("listAllBaseClz")
    @ResponseBody
    public List<ClassGrade> listAllBaseClz() {
        return classGradeService.listAllBaseClz();
    }

    /*查询出所有的大神班*/
    @RequestMapping("listAllGodClz")
    @ResponseBody
    public List<ClassGrade> listAllGodClz() {
        return classGradeService.listAllGodClz();
    }
}
